package c.x.jy.wexin.config;

import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*@SuppressWarnings("all")
@Configuration(proxyBeanMethods = false)
@Import(EnableWebMvcConfiguration.class)
@EnableConfigurationProperties({ WebMvcProperties.class, ResourceProperties.class })
@Order(0 )*/
public class MyMvcConfig implements WebMvcConfigurer {
/*
	private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[] {

			"classpath:/static/", };

	
	 * @Override public void addViewControllers(ViewControllerRegistry registry) {
	 * 
	 * registry.addViewController("/").setViewName("forward:/index.html");
	 * 
	 * 
	 * registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
	 * WebMvcConfigurer.super.addViewControllers(registry); }
	 

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 解决静态资源无法访问

		registry.addResourceHandler("/**").addResourceLocations("classpath:/static/")
				.addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
		WebMvcConfigurer.super.addResourceHandlers(registry);
	}

	@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
		converters.add(getMappingJackson2HttpMessageConverter());
	}

	*//**
	 * JSON全局日期转换器
	 *//*
	@Bean
	public MappingJackson2HttpMessageConverter getMappingJackson2HttpMessageConverter() {
		MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
		// 设置日期格式
		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.setDateFormat(CustomDateFormat.instance);
		objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
		// 设置中文编码格式
		List<MediaType> list = new ArrayList<MediaType>();
		list.add(MediaType.APPLICATION_JSON_UTF8);
		mappingJackson2HttpMessageConverter.setSupportedMediaTypes(list);
		return mappingJackson2HttpMessageConverter;
	}

	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		// 单个文件最大 5M
		factory.setMaxFileSize(DataSize.ofBytes(20 * 1024 * 1024)); // KB,MB
		/// 设置总上传数据总大小
		factory.setMaxRequestSize(DataSize.ofBytes(20 * 1024 * 1024));

		return factory.createMultipartConfig();
	}

	@Bean("multipartResolver")
	public MultipartResolver feignFormEncoder() {
		CommonsMultipartResolver c = new CommonsMultipartResolver();
		c.setDefaultEncoding("UTF-8");
		c.setMaxUploadSize(20 * 1024 * 1024);
		return c;
	}

	@Bean
	public FilterRegistrationBean corsFilter() {
		UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
		CorsConfiguration config = new CorsConfiguration();
		config.setAllowCredentials(true);
		config.addAllowedOrigin("*");
		config.addAllowedHeader("*");
		config.addAllowedMethod("*");
		source.registerCorsConfiguration("/**", config);
		FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
		bean.setOrder(0);
		return bean;

	}
*/
}
